package base;

import java.util.ArrayList;
import java.util.List;

//子类：Student 继承自 Person，扩展专业与选课功能
public class Student extends Person {
    private String major;                // 专业
    private List<Course> selectedCourses; // 已选课程列表

    // 构造方法：调用父类构造方法
    public Student(String id, String name, String gender, String major) {
        super(id, name, gender);
        this.major = major;
        this.selectedCourses = new ArrayList<>();
    }

    // 选课
    public void selectCourse(Course course) {
        if (selectedCourses.contains(course)) {
            System.out.println("学生 " + name + " 已选修《" + course.getCourseName() + "》，无法重复选课。");
        } else {
            selectedCourses.add(course);
            System.out.println("学生 " + name + " 成功选修《" + course.getCourseName() + "》");
        }
    }

    // 退课
    public void dropCourse(Course course) {
        if (selectedCourses.contains(course)) {
            selectedCourses.remove(course);
            System.out.println("学生 " + name + " 已退选《" + course.getCourseName() + "》");
        } else {
            System.out.println("学生 " + name + " 未选修该课程，无法退课。");
        }
    }

    // 打印课表
    public void printCourseSchedule() {
        System.out.println("=== " + major + " 专业学生 " + name + " 的课表 ===");
        if (selectedCourses.isEmpty()) {
            System.out.println("暂无选课记录。");
        } else {
            for (Course c : selectedCourses) {
                System.out.println("- " + c.getCourseName() + "（" + c.getTime() + "）");
            }
        }
    }
}

